#include "Fire.h"
#include "RSManager.h"
#include "Box.h"
#include <d3dx9.h>
#include "Object.h"
#include "Sprite.h"

#define V_MOVE_FIRE 1.4f
#define LEFT_SIDE 135
#define RIGHT_SIDE LEFT_SIDE + 245
Fire::Fire(Box* box): Object(box,Obj_Anti)	
{
}


Fire::~Fire(void)
{
}

void Fire::init()
{
	
	this->_sprite = RSManager::getInstance()->getSprite(FIRE);
	_box->_size = _sprite->getRenderSize();
	dx = 1;
	float lDx = abs(_box->getLeft() - LEFT_SIDE);
	float lDy = abs(_box->getRight() - RIGHT_SIDE);
	if(lDy > lDx)
	{
		dx = -1.0f;
	}
	else
	{
		dx = 1.0f;
	}
	_hits = -1.0f;
	_isAlive =  true;
	delay = 0;
	
}

void Fire::update()
{
	delay += GAME_TIME;
	if(delay >100)
	{
		delay = 0;
		_sprite->Next();
	}
	if(_box->getLeft() < LEFT_SIDE)
	{
		dx = 1.0f;
	}
	if( _box->getRight() > RIGHT_SIDE)
	{
		dx = -1.0f;
	}
	_box->_position.x += dx * V_MOVE_FIRE;
}

void Fire::render()
{
	_sprite->Render(_box->_position);
}

Box* Fire::getCollisionBox()
{
	_colBox->_position = _box->_position;
	_colBox->_size = _box->_size;
	_colBox->_v = _box->_v;
	_colBox->_size.x /= 3;
	_colBox->_size.y /= 3;
	_colBox->_position.x += _colBox->_size.x;
	_colBox->_position.y += _colBox->_size.y;
	return _colBox;
}
